package com.example.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class jdbcController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/insert")
    public String insert(Integer id,String name) {
        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(name)) {
            return "参数异常";
        }
        jdbcTemplate.execute("insert into test1 (`id`,`name`) value (\"" + id + "\",\"" + name + "\")");
        return "insert语句执行完毕";
    }
}
